import React, { useEffect } from 'react'

import { jia, jian, asynjia, asynjian } from "../store/slices/countSlies"
import { zanadd, zansubtract, asynaddzan, asynsubtractzan } from '../store/slices/zanSlies'
import { useSelector, useDispatch } from "react-redux"
import {getHitokoto} from "../store/slices/hitokoto"
import LoL from '../pages/LoL/LoL'


export default function Redux() {
    let {zan,con,hito} = useSelector((state) => {
   
        return state
    })
 
let dispatch = useDispatch()

    useEffect(()=>{
        dispatch(getHitokoto()) 
    },[])

    let add = () => {
     
        dispatch(jia(1))


    }
    let subtract = () => {
       dispatch(jian(2))
 
    }
    // 异步加
    let asyncadd = () => {
       dispatch(asynjia(3))

    }
    //    异步减
    let asyncsubtract = () => {
        dispatch(asynjian(2))


    }
    // 同步加点赞
    let addzan = () => {
       dispatch(zanadd(1))


    }
    // 同步减点赞
    let subtractzan = () => {
     dispatch(zansubtract(2))


    }
    // 异步点赞加
    let asyncaddzan = () => {
      dispatch(asynaddzan(3))

    }
    // 异步点赞加
    let asyncsubtractzan = () => {
       dispatch(asynsubtractzan(2))
   
    }
    // 获取一句话
    let next = ()=>{
        dispatch(getHitokoto())
    }
    return (
        <div>
            <LoL></LoL>
            <h1 onClick={next} >想对你说的一句话:{hito.value}</h1>
            <hr />
            <h1>store中的数据是：{con.value}</h1>
            <button onClick={add}>+++++++++++11111111111</button>
            <button onClick={subtract}>-----------22222222222</button>
            <button onClick={asyncadd}>异步加++++++++++3</button>
            <button onClick={asyncsubtract}>异步减-----------2</button>
            <hr />
            <h1>点赞数是：{zan.value}</h1>
            <button onClick={addzan}>+++++++++++11111111111</button>
            <button onClick={subtractzan}>-----------22222222222</button>
            <button onClick={asyncaddzan}>异步加++++++++++3</button>
            <button onClick={asyncsubtractzan}>异步减-----------2</button>
        </div>
    )
}
